import {reqCategoryList,reqGetBannerList,reqFloorList} from '@/api';

// home仓库
const state = {
  //state中数据默认的初始值不能瞎写,服务器返回对象,服务器返回数据,要根据服务器接口返回值定
  categoryList: [],
  //轮播图数据
  bannerList: [],
  //floor数据
  floorList: [],
};
const mutations = {
  CATEGORYLIST(state,categoryList) {
    state.categoryList = categoryList;
  },
  GETBANNERLIST(state,bannerList) {
    state.bannerList = bannerList
  },
  GETFLOORLIST(state,floorList) {
    state.floorList = floorList
  }
};
const actions = {
  // 通过api中的接口调用函数,来接收或者发送请求
  async categoryList({commit}) {
    let result = await reqCategoryList();
    if( result.code == 200 ){
      commit("CATEGORYLIST",result.data)
    }
  },
  async getBannerList({commit}){
    let result = await reqGetBannerList();
    if(result.code == 200){
      commit("GETBANNERLIST",result.data)
    }
  },
  async getFloorList({commit}){
    let result = await reqFloorList();
    if(result.code == 200){
      commit('GETFLOORLIST',result.data)
    }
  }
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters
}